www.gusucode.com > VC++ 模仿MSN界面 > VC++ 模仿MSN界面/gusucode/MSN/UserChat.cpp
//Download by http://www.NewXing.com // UserChat.cpp : implementation file // #include "stdafx.h" #include "MSN.h" #include "UserChat.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CUserChat dialog CUserChat::CUserChat(CWnd* pParent /*=NULL*/) : CDialog(CUserChat::IDD, pParent) { //{{AFX_DATA_INIT(CUserChat) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CUserChat::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CUserChat) DDX_Control(pDX, IDC_BUTTON_SWITCH, m_SwitchButton); DDX_Control(pDX, IDC_BUTTON_SEND, m_BtnSender); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CUserChat, CDialog) //{{AFX_MSG_MAP(CUserChat) ON_WM_SIZE() ON_WM_NCCREATE() ON_BN_CLICKED(IDC_BUTTON_SWITCH, OnButtonSwitch) ON_WM_ERASEBKGND() ON_WM_GETMINMAXINFO() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CUserChat message handlers BOOL CUserChat::OnInitDialog() { CDialog::OnInitDialog(); CRect rect; GetClientRect(rect); m_right.Create(IDD_CHAT_RIGHT,this); m_right.ShowWindow(SW_NORMAL); m_right.MoveWindow(rect.Width()-140,57,120,rect.Height()-85-19); CRect rcRight; m_right.GetClientRect(rcRight); m_left.Create(IDD_CHAT_LEFT,this); m_left.ShowWindow(SW_NORMAL); m_left.MoveWindow(7,57,rect.Width()-35-rcRight.Width(),rect.Height()-85-19); m_SwitchButton.MoveWindow(rect.Width()-12,57,12,31); CButton *btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND); SetWindowSkinResID(btn->m_hWnd, 500); btn->MoveWindow(rect.Width()-245, rect.Height()-40, 69, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND2); SetWindowSkinResID(btn->m_hWnd, 501); btn->MoveWindow(rect.Width()-171, rect.Height()-40, 23, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND3); btn->MoveWindow(7, rect.bottom-48, 51, 23); CStatic *tic = (CStatic *)GetDlgItem(IDC_STATICAD); tic->GetClientRect(rcRight); tic->MoveWindow(9, rect.Height()-12, rcRight.Width(), rcRight.Height()); return TRUE; } void CUserChat::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); if (m_right.m_hWnd==NULL) return; if (isOpen) { m_right.MoveWindow(cx-140,57,120,cy-85-19); CRect rcRight; m_right.GetClientRect(rcRight); m_left.MoveWindow(7,57,cx-35-rcRight.Width(),cy-85-19); CButton *btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND); btn->MoveWindow(cx-245, cy-40, 69, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND2); btn->MoveWindow(cx-171, cy-40, 23, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND3); btn->MoveWindow(7, cy-48, 51, 23); } else { m_right.MoveWindow(cx-140,57,0,cy-85-19); CRect rcRight; m_right.GetClientRect(rcRight); m_left.MoveWindow(7,57,cx-30,cy-85-19); CButton *btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND); btn->MoveWindow(cx-120, cy-40, 69, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND2); btn->MoveWindow(cx-46, cy-40, 23, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND3); btn->MoveWindow(7, cy-48, 51, 23); } CRect rcRight; CStatic *tic = (CStatic *)GetDlgItem(IDC_STATICAD); tic->GetClientRect(rcRight); tic->MoveWindow(9, cy-12, cx, cy); m_SwitchButton.MoveWindow(cx-12,57,12,31); Invalidate(); } BOOL CUserChat::OnNcCreate(LPCREATESTRUCT lpCreateStruct) { if (!CDialog::OnNcCreate(lpCreateStruct)) return FALSE; SetWindowSkinResID(m_hWnd, 999); return TRUE; } void CUserChat::OnButtonSwitch() { isOpen = !isOpen; CRect rect; GetClientRect(rect); int cx = rect.Width(); int cy = rect.Height(); if (isOpen) { m_right.MoveWindow(cx-140,57,120,cy-85-19); CRect rcRight; m_right.GetClientRect(rcRight); m_left.MoveWindow(7,57,cx-35-rcRight.Width(),cy-85-19); CButton *btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND); btn->MoveWindow(cx-245, cy-40, 69, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND2); btn->MoveWindow(cx-171, cy-40, 23, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND3); btn->MoveWindow(7, cy-48, 51, 23); } else { m_right.MoveWindow(cx-140,57,0,cy-85-19); CRect rcRight; m_right.GetClientRect(rcRight); m_left.MoveWindow(7,57,cx-30,cy-85-19); CButton *btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND); btn->MoveWindow(cx-120, cy-40, 69, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND2); btn->MoveWindow(cx-46, cy-40, 23, 21); btn = (CButton *)GetDlgItem(IDC_BUTTON_SEND3); btn->MoveWindow(7, cy-48, 51, 23); } m_SwitchButton.MoveWindow(cx-12,57,12,31); } BOOL CUserChat::OnEraseBkgnd(CDC* pDC) { //CRect rc; //GetClientRect(rc); //DrawSkinImageRes(pDC->m_hDC, rc, "chat.bmp", 35, 35, 82, 14, FALSE); return TRUE; return CDialog::OnEraseBkgnd(pDC); } void CUserChat::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { lpMMI->ptMinTrackSize.x = 400;// m_MinSize为最小尺寸 lpMMI->ptMinTrackSize.y = 415;// m_MinSize为最小尺寸 CDialog::OnGetMinMaxInfo(lpMMI); }